//=============================================================================
// File name:   seg7_decode.v
// Author:      Cody Cziesler
//
// Description: This module will take in a 4-bit binary number and convert it
//              to the seven-segment output. The defines for the segments are
//              found in include.v.
//
//=============================================================================
`include "include.v"

module seg7_decode (
  input  wire       en,      // The active-high enable
  input  wire [3:0] seg_in,  // The 4-bit input signal
  output wire [6:0] seg_out  // The decoded 7-bit segment output
);

// A register to hold the output value before it is muxed
reg [6:0] seg_out_r;

// Turn off the segment when enable is low
assign seg_out = (en == 1'b1) ? seg_out_r : 7'b0;

// Decode the 7-segment output based on the binary 4-bit input
always @(*) begin
  case (seg_in)
    4'h0:    seg_out_r = `SEG_0;
    4'h1:    seg_out_r = `SEG_1;
    4'h2:    seg_out_r = `SEG_2;
    4'h3:    seg_out_r = `SEG_3;
    4'h4:    seg_out_r = `SEG_4;
    4'h5:    seg_out_r = `SEG_5;
    4'h6:    seg_out_r = `SEG_6;
    4'h7:    seg_out_r = `SEG_7;
    4'h8:    seg_out_r = `SEG_8;
    4'h9:    seg_out_r = `SEG_9;
    4'hA:    seg_out_r = `SEG_A;
    4'hB:    seg_out_r = `SEG_B;
    4'hC:    seg_out_r = `SEG_C;
    4'hD:    seg_out_r = `SEG_D;
    4'hE:    seg_out_r = `SEG_E;
    4'hF:    seg_out_r = `SEG_F;
    default: seg_out_r = `SEG_0;
  endcase
end

endmodule
